package com.tensquare.user.dao;

import com.tensquare.user.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import sun.font.TrueTypeFont;

/**
 * @Author:zimmor
 * @Date: 2021/3/11 11:56
 * @Description 数据层接口
 * @version: 1.0.0
 */

public interface UserDao extends JpaRepository<User, String>, JpaSpecificationExecutor {
    /**
     * 当前用户的关注数加一
     * @param userid
     */
    @Query(value = "UPDATE tb_user SET followcount = followcount+1 WHERE id = ?", nativeQuery= true)
    @Modifying
    void followcountAdd(String userid);

    /**
     * 被关注的用户粉丝数加一
     * @param friendid
     */
    @Query(value="UPDATE tb_user SET fanscount = fanscount+1 WHERE id = ?", nativeQuery=true)
    @Modifying
    void fanscountAdd(String friendid);

    /**
     * 当前用户的关注数减一
     * @param userid
     */
    @Query(value="UPDATE tb_user SET followcount = followcount-1 WHERE id = ?", nativeQuery=true)
    @Modifying
    void followCountReduce(String userid);

    /**
     * 被取消关注的用户粉丝数减一
     * @param friendid
     */
    @Query(value="UPDATE tb_user SET fanscount = fanscount-1 WHERE id = ?", nativeQuery=true)
    @Modifying
    void fanscountReduce(String friendid);
}
